#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2018/11/27 18:29
# @Author  : yangdy
# @Email   : yangdy@egu360.com
# @File    : 中级-TaskScheduler.py
# @Software: PyCharm
from utils.main import main, opt_list


class Solution:
    def leastInterval(self, tasks, n):
        """
        :type tasks: List[str]
        :type n: int
        :rtype: int
        """
        m = {}
        for key in tasks:
            if m.get(key):
                m[key] += 1
            else:
                m[key] = 1
        data = []
        for key in m.keys():
            data.append(m[key])
        data.sort()
        data.reverse()
        c = 0
        for i in range(len(data)):
            c += 1 if data[i] == data[0] else 0
        return max(len(tasks), (data[0]-1)*(n+1)+c)


def opt(tasks, n):
    solve = Solution()
    print(tasks)
    print(n)
    print('ans:', solve.leastInterval(tasks, n))


def opt1():
    tasks = ["A", "A", "A", "B", "B", "B"]
    n = 2
    opt(tasks, n)


def opt2():
    tasks = ["A", "A", "B", "B", "B", "C"]
    n = 2
    opt(tasks, n)


if __name__ == '__main__':
    opt_list.append(opt1)
    opt_list.append(opt2)
    main()
